import 'package:flutter/material.dart';
import 'package:flutter1911/page/index_page.dart';
import 'package:flutter1911/provider/cart_provider.dart';
import 'package:flutter1911/provider/category_provider.dart';
import 'package:flutter1911/provider/counter.dart';
import 'package:flutter1911/provider/detai_iInfo_provider.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:provider/provider.dart';
import 'package:fluro/fluro.dart';
import 'router/application.dart';
import 'package:flutter1911/router/routers.dart';

///Provider使用方法:
///1.创建一个Provider,相当于全局变量的一个bean,有set,get方法,有属性
///2.需要在main中注册一个Provider(create: (_) => T())
///3.获取一个使用context.watch<T>().value
///4.保存/修改一个值使用Provider.of<T>(context, listen: false).increment();
///5.<T>的泛型一定要添加,否则Provider找不到对应的对象

void main() {
  runApp(MultiProvider(
    providers: [
      ChangeNotifierProvider(create: (_) => Counter()),
      ChangeNotifierProvider(create: (_) => CategoryProvider()),
      ChangeNotifierProvider(create: (_) => DetailInfoProvider()),
      ChangeNotifierProvider(create: (_) => CartProvider()),
    ],
    child: const MyApp(),
  ));
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final router = FluroRouter();
    Routers.configureRouters(router);
    Application.router = router;
    return ScreenUtilInit(
      designSize: const Size(750, 1334),
      minTextAdapt: true,
      splitScreenMode: true,
      builder: (BuildContext context, Widget? child) {
        return MaterialApp(
          title: '百姓生活+',
          debugShowCheckedModeBanner: false,
          theme: ThemeData(
              primaryColor: Colors.pink,
              colorScheme:
                  const ColorScheme.light().copyWith(primary: Colors.pink)),
          //根据明暗主题切换颜色
          //设置主题颜色
          home: IndexPage(),
          onGenerateRoute: Application.router!.generator,
        );
      },
    );
  }
}
